<template>
  <el-container style="padding:20px;height:660px">
    <el-header>
      <div class="title">发布课程通告</div>
    </el-header>
    <el-main>
      <el-form style="margin-left:25px">
        <el-form-item label="课程通告标题">
          <el-input
            v-model="announcementData.title"
            size="small"
            style="margin-left:50px;width:300px;"
            placeholder="请输入课程通告标题"
          />
        </el-form-item>
      </el-form>
      <div class="contentTile" style="margin-left:25px;margin-top:80px">课程通告内容</div>
      <el-input
        type="textarea"
        placeholder="请输入课程通告内容"
        v-model="announcementData.content"
        style="margin-top:20px;margin-left:25px;"
        class="content"
        resize="none"
      ></el-input>
      <el-button
        style="margin-left:25px;margin-top:50px"
        class="btn"
        @click="postAnnouncement"
      >发布课程通告</el-button>
    </el-main>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      announcementData: {
        title: "",
        content: ""
      }
    };
  },
  methods: {
    postAnnouncement() {
      this.$confirm("确认发布课程公告？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          // 这里填写向后端发请求的内容
          let options = {
            title: this.announcementData.title,
            content: this.announcementData.content,
            sections: this.$store.state.temp_courseSections
          };

          // 我先假装我请求成功了
          this.$http
            .post(this.$api.CourseMonitorPublishAnnouncement, options)
            .then(resp => {
              if (resp.success) {
                this.$myMessage.success(this, "发布课程通告成功");
              } else {
                this.$handleFailResp(this, resp);
              }
            });

          // 先显示1秒钟的提交成功信息之后再刷新
          setTimeout(() => {
            this.$router.go(0);
          }, 1000);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消发布"
          });
        });
    }
  }
};
</script>

<style lang="less" scoped>
.title {
  font-size: 20px;
  font-weight: 700;
  font-family: "Arial Negreta", "Arial Normal", "Arial";
  color: #2d6db0;
}

/deep/ .el-input__inner {
  padding: 0 10px;
  border-radius: 0;
  font-size: 14px;
  color: #333333;
}

/deep/ .el-form-item__label {
  color: #333333;
  font-size: 16px;
  font-family: "Arial Normal", "Arial";
}

.contentTile {
  color: #333333;
  font-size: 16px;
  font-family: "Arial Normal", "Arial";
  font-weight: 500;
}

.content {
  width: 500px;
}

/deep/ .el-textarea__inner {
  border-radius: 0;
  height: 250px;
  padding: 10px 10px;
  font-size: 16px;
  color: #333333;
}

.btn {
  background-color: #2d6db0;
  width: 150px;
  color: #f2f2f2;
}
</style>
